<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>使用js传参方式上传图片</title>
    <script src="http://a.tbcdn.cn/s/kissy/1.2.0/kissy-min.js" charset="utf-8"></script>

</head>
<body>
<h2>使用js传参方式上传图片</h2>

<div class="grid">
    <input type="image-uploader" class="g-u" id="J_JsUploaderBtn" value="上传图片" >
</div>
<ul id="J_JsUploaderQueue" class="grid">

</ul>
<script>
    var S = KISSY,
    //包路径，实际使用请直接配置为"http://a.tbcdn.cn/s/kissy/"
            path = S.Config.debug && "../../../../../../" || "http://a.tbcdn.cn/s/kissy/";
    S.config({
        packages:[
            {
                name:"gallery",
                path:path,
                charset:"utf-8"
            }
        ]
    });

    KISSY.use('gallery/form/1.3/uploader/imageUploader', function (S, ImageUploader) {

        var imageUploader = new ImageUploader('#J_JsUploaderBtn','#J_JsUploaderQueue',{
            // 文件域
            name:"Filedata",
            //处理上传的服务器端脚本路径
            action:"upload.php",
            //用于放服务器端返回的url的隐藏域
            urlsInputName:"jsImageUrls",
            //最多上传个数
            max:3,
            //图片最大允许大小
            maxSize:500
        });
        imageUploader.on('error',function(ev){
            var uploader = ev.uploader;
            var max = uploader.get('max');
            var queue = uploader.get('queue');
            var files = queue.getFiles('success');
            if (ev.rule == 'max' && files.length >= max ) {
                alert('队列已满，不能上传！');
            }
        });
        imageUploader.render();
    })

</script>
</body>
</html>